package com.ransj.iphone.view;

import com.ransj.iphone.IKeyListener;
import com.ransj.iphone.utils.ILog;

import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

/**
 * abstract view
 * 
 * @author ranshengju
 * 
 */
public abstract class AbsView {
	private static final String TAG = AbsView.class.getSimpleName();
	protected View mMainView;
	protected LayoutParams mWMParams;
	protected WindowManager mWMManager;
	protected IKeyListener mKeyListener;

	public void setWindowManager(WindowManager manager) {
		try {
			mWMManager = manager;
			manager.addView(mMainView, mWMParams);
		} catch (Exception e) {
			ILog.getInstance().e(TAG, e);
		}
	}

	public void dispathWindowManager() {
		try {
			if (mWMManager != null) {
				mWMManager.removeView(mMainView);
			}
		} catch (Exception e) {
			ILog.getInstance().e(TAG, e);
		}
	}
	
	public void updatePosition(int x, int y){
		if(mWMManager != null && mWMParams != null && mMainView != null){
			mWMParams.x = x;
			mWMParams.y = y;
			mWMManager.updateViewLayout(mMainView, mWMParams);
		}
	}
}
